<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/form.xsl" />
	<xsl:include href="../photos/blocks.xsl" />
	<xsl:include href="ownerBar.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/users/profile.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/owner-bar.js" />
			<script type="text/javascript" src="{$baseURI}/js/twitter.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
						
					<div class="block">
						<div class="header">Фотоальбомы пользователя</div>
						<div class="content user-photoalbums-list">
							<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbums/', response/@user-id))/data/response" mode="block-user-albums" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
				</div>
	
				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response/object[@type='user']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="login" select="property[@name='login']/value" />
		<xsl:param name="typeId" select="@type-id" />
		
		<div class="user-profile">
			<div class="avatar">
				<div class="border">
					<img>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='name']/value" />
						</xsl:attribute>
						<xsl:attribute name="src">
							<xsl:if test="property[@name='avatar']/value = ''">
								<xsl:value-of select="concat ($baseURI, '/images/default-user-avatar-100.png')" />
							</xsl:if>
							<xsl:if test="property[@name='avatar']/value != ''">
								<xsl:value-of select="concat ($baseURI, '/thumb_100_100', property[@name='avatar']/value)" />
							</xsl:if>
						</xsl:attribute>
					</img>
					
					<i class="corner-mask-white-border-5 tl"></i>
					<i class="corner-mask-white-border-5 tr"></i>
					<i class="corner-mask-white-border-5 br"></i>
					<i class="corner-mask-white-border-5 bl"></i>
				</div>
			</div>
			
			<div class="bar">
				<xsl:apply-templates select="." mode="ownerbar">
					<xsl:with-param name="avatarOff">1</xsl:with-param>
					<xsl:with-param name="showName">1</xsl:with-param>
				</xsl:apply-templates>
			</div>
			
			
			<div class="properties">
				<xsl:apply-templates select="property" />
				
				<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id))/data/response" mode="joined-blogs" />
				
				<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id, ';moderator'))/data/response" mode="moderate-blogs" />
				
				<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id, ';admin'))/data/response" mode="admin-blogs" />
				
				<xsl:apply-templates select="document(concat('xmodule://users/getFriendsList/', @id))/data/response" mode="friends" />
			</div>
		</div>
	</xsl:template>
	
	<xsl:template match="property[@name='login']" />
	<xsl:template match="property[@name='password']" />
	<xsl:template match="property[@name='group']" />
	<xsl:template match="property[@name='avatar']" />
	<xsl:template match="property[@name='name']" />
	<xsl:template match="property[@name='email']" />
	<xsl:template match="property[@name='rating']" />
	<xsl:template match="property[@name='rating_votes']" />
	<xsl:template match="property[@name='interests']" />
	<xsl:template match="property[@name='count_friends']" />
	
	<xsl:template match="response" mode="joined-blogs">
		<xsl:param name="cnt" select="count(object)" />
		
		<xsl:if test="count(object) != 0">
			<dl>
				<dt>Читает:</dt>
				<dd>
					<xsl:for-each select="object">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="concat($baseURI, '/blog/', property[@name='blog_alias']/value)" />
							</xsl:attribute>
							<xsl:value-of select="property[@name='blog_title']/value" />
						</a>
						
						<xsl:if test="position() != $cnt">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="response" mode="moderate-blogs">
		<xsl:param name="cnt" select="count(object)" />
		
		<xsl:if test="$cnt != 0">
			<dl>
				<dt>Модерирует:</dt>
				<dd>
					<xsl:for-each select="object">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="concat($baseURI, '/blog/', property[@name='blog_alias']/value)" />
							</xsl:attribute>
							<xsl:value-of select="property[@name='blog_title']/value" />
						</a>
						
						<xsl:if test="position() != $cnt">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="response" mode="admin-blogs">
		<xsl:param name="cnt" select="count(object)" />
		
		<xsl:if test="count(object) != 0">
			<dl>
				<dt>Администрирует:</dt>
				<dd>
					<xsl:for-each select="object">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="concat($baseURI, '/blog/', property[@name='blog_alias']/value)" />
							</xsl:attribute>
							<xsl:value-of select="property[@name='blog_title']/value" />
						</a>
						
						<xsl:if test="position() != $cnt">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='livejournal_login']">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<a class="livejournal">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://', value,'.livejournal.com')" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='twitter_login']">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<a class="twitter">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://twitter.com/', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='habr_login']">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<a class="habr">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://', value, '.habrahabr.ru')" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='vkontakte_id']">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<a class="vkontakte">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://vkontakte.ru/id', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='icq']">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<a class="icq">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://wwp.icq.com/scripts/contact.dll?msgto=', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='interests']">
		<xsl:param name="cnt" select="count (value)" />
		
		<xsl:if test="$cnt &gt; 0">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<xsl:for-each select="value">
						<xsl:value-of select="." />
						<xsl:if test="position() != $cnt">
							<xsl:text>, </xsl:text>
						</xsl:if> 
					</xsl:for-each>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='gender']">
		<xsl:param name="cnt" select="count (value)" />
		
		<xsl:if test="$cnt &gt; 0">
			<dl>
				<dt>
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</dt>
				<dd>
					<xsl:choose>
						<xsl:when test="value = 'man'">
							<xsl:text>мужской</xsl:text>
						</xsl:when>
						<xsl:when test="value = 'woman'">
							<xsl:text>женский</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>неопределенный</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property">
		<xsl:if test="value != ''">
			<dl>
				<dt>
					<xsl:value-of select="title" />:
				</dt>
				<dd>
					<xsl:value-of select="value" />
				</dd>
			</dl>
		</xsl:if>
	</xsl:template>
	
	<!-- FRIENDS -->
	<xsl:template match="response" mode="friends">
		<dl>
			<dt>Друзья:</dt>
			<dd>
				<xsl:if test="count (object) = 0">
					<xsl:text>нет</xsl:text>
				</xsl:if>
				<xsl:if test="count (object) &gt; 0">
					<ul class="friends-list">
						<xsl:apply-templates select="object" mode="friend-item" />
					</ul>
				</xsl:if>
			</dd>
		</dl>
	</xsl:template>
	
	<xsl:template match="object[@type='friend']" mode="friend-item">
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="href" select="concat ($baseURI, '/user/', $userLogin)" />
		<xsl:param name="avatar" select="property[@name='user_avatar']/value" />
		
		<li>
			<a class="avatar" href="{$href}">
				<img alt="{$userLogin}">
					<xsl:attribute name="src">
						<xsl:if test="$avatar = ''">
							<xsl:value-of select="concat ($baseURI, '/images/default-avatar-small.png')" />
						</xsl:if>
						<xsl:if test="$avatar != ''">
							<xsl:value-of select="concat ($baseURI, '/thumb_24_24', $avatar)" />
						</xsl:if>
					</xsl:attribute>
				</img>
			</a>
			<a class="name" href="{$href}">
				<xsl:value-of select="$userLogin" />
			</a>
		</li>
	</xsl:template>
	
</xsl:stylesheet>